#include<bits/stdc++.h>
using namespace std;
int n;
typedef vector<vector<int>> mat;
mat zero(){
    return mat(n,vector<int>(n));
}
mat eye(){
    mat res = zero();
    for(int i = 0;i < n;i++){
        res[i][i] = 1;
    }
    return res;
}
const int MOD = 998244353;
mat operator*(const mat &a,const mat &b){
    mat res = zero();
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            for(int k = 0;k < n;k++){
                res[i][j] = (res[i][j] + 1ll*a[i][k]*b[k][j]%MOD)%MOD;
            }
        }
    }
    return res;
}
mat operator+(const mat &a,const mat &b){
    mat res = a;
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            res[i][j] = (res[i][j] + b[i][j])%MOD;
        }
    }
    return res;
}
tuple<mat,mat,mat> operator*(const tuple<mat,mat,mat> &v1,const tuple<mat,mat,mat> &v2){
    return make_tuple(get<0>(v1) * get<0>(v2),get<1>(v1)*get<1>(v2),get<0>(v1)*get<2>(v2)*get<1>(v1) + get<2>(v1));
}
tuple<mat,mat,mat> qpow(tuple<mat,mat,mat> v1,__int128 p){
    tuple<mat,mat,mat> res = make_tuple(eye(),eye(),zero());
    while(p){
        if(p & 1){
            res = res*v1;
        }
        v1 = v1*v1;
        p >>= 1;
    }
    return res;
}
tuple<mat,mat,mat> f(__int128 a,__int128 b,__int128 c,__int128 n,const tuple<mat,mat,mat> &u,const tuple<mat,mat,mat> &r){
    if(n <= 0){
        return make_tuple(eye(),eye(),zero());
    }
    if((a*n + b)/c < 1){
        return qpow(r,n);
    }
    
    if(a > c){
        return f(a%c,b,c,n,u,qpow(u,a/c)*r);
    }else{
        return qpow(r,(c - b - 1)/a)*u*f(c,(c - b - 1)%a,a,(a*n + b)/c - 1,r,u)*qpow(r,n - (c*((a*n + b)/c) - b - 1)/a);
    }
}
int main(){
    long long p,q,r,l;
    cin>>p>>q>>r>>l;
    cin>>n;
    mat A = zero();
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            cin>>A[i][j];
        }
    }
    mat B = zero();
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            cin>>B[i][j];
        }
    }
    tuple<mat,mat,mat> U = make_tuple(eye(),B,zero());
    tuple<mat,mat,mat> R = make_tuple(A,eye(),A);
    tuple<mat,mat,mat> res = qpow(U,r/q)*f(p,r%q,q,l,U,R);
    for(int i = 0;i < n;i++){
        for(int j = 0;j < n;j++){
            cout<<get<2>(res)[i][j]<<' ';
        }
        cout<<'\n';
    }
}